<template>
  <svg :class="svgClass" aria-hidden="true">
    <use :xlink:href="svgName"></use>
  </svg>
</template>

<script>
import { computed, onMounted } from "@vue/composition-api";
export default {
  name: "svgIcon",
  props: {
    iconClass: {
      type: String,
      default: ""
    },
    iconName: {
      type: String,
      default: ""
    }
  },
  setup(props) {
    const svgName = computed(() => `#icon-${props.iconName}`);
    const svgClass = computed(() => {
      if (props.iconClass) {
        return `svg-icon ${props.iconClass}`;
      }
      return `svg-icon`;
    });

    //组件挂载完成中加载的生命周期
    onMounted(() => {});
    return {
      svgClass,
      svgName
    };
  }
};
</script>

<style lang="scss" scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  font-size: 20px;
  // 设置了这个属性之后 svg图片的颜色就能通过属性进行改变
  fill: currentColor;
}
</style>
